class Solution {
public:
    ListNode* removeElements(ListNode* head, int val) {
        while(head!=NULL&&head->val==val){
            ListNode* drop=head;
            head=head->next;
            delete drop;
            
        }
        ListNode* ind=head;
        while(ind!=NULL&&ind->next!=NULL){
            if(ind->next->val==val){
                ListNode* drop=ind->next;
                ind->next=drop->next;
                delete drop;
            }else{
                ind=ind->next;
            }
        }
        return head;
    }
};